﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Soft.Service
{
    public abstract class BaseRemoteControlProcessor : SoftObject
    {


        /// <summary>
        /// 将json参数反序列为T对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="jsonParam">参数字符串</param>
        /// <param name="parameter">参数</param>
        /// <returns></returns>
        public Result ConvertParams<T>(string jsonParam, out T parameter)
        {
            Result result = new Result();
            try
            {
                parameter = JsonConvertHelper.FormJson<T>(jsonParam);
            }
            catch (Exception exception)
            {
                result.AddError(exception, null);
                parameter = default(T);
            }
            return result;
        }


        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="jsonParam"></param>
        /// <returns></returns>
        public abstract ResultJson Processing(string jsonParam);


        /// <summary>
        /// 获取客户端参数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json"></param>
        /// <returns></returns>
        protected ResultData<T> GetClientRemoteControlParametes<T>(string json)
        {
            ResultData<T> resultData = new ResultData<T>();
            try
            {
                resultData.Data = JsonConvertHelper.FormJson<T>(json);
            }
            catch
            {
                resultData.AddError("输入的远程控制参数格式有错误。", null);
            }
            return resultData;
        }

    }
}
